package com.demo.java.OD551_600.OD591;

import java.util.Scanner;
import java.util.*;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【二叉树中序遍历(B卷-100分)】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146571317
 */
public class OdMain {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        LinkedList<Integer> left_pos = new LinkedList<>();
        LinkedList<String> container = new LinkedList<>();

        int i = 0;
        while (true) {
            if (i >= str.length()) {
                System.out.println(container.get(0));
                break;
            } else {
                if (str.charAt(i) == '}') {
                    // 处理右括号，反转括号内的内容
                    String temp = "";
                    int new_idx = left_pos.get(left_pos.size() - 1) + 1;
                    left_pos.removeLast();
                    while (true) {
                        if (new_idx >= container.size()) {
                            break;
                        } else {
                            temp += container.remove(new_idx);
                        }
                    }
                    String[] split = temp.split(",");
                    container.removeLast();
                    String new_root = container.get(container.size() - 1);
                    container.removeLast();
                    container.addLast(split[0] + new_root + (split.length > 1 ? split[1] : ""));
                    i += 1;
                    continue;
                } else if (str.charAt(i) == '{') {
                    // 处理左括号，记录当前位置
                    left_pos.addLast(container.size());
                    container.addLast(str.charAt(i) + "");
                } else {
                    // 普通字符直接加入到容器中
                    container.addLast(str.charAt(i) + "");
                }
            }
            i += 1;
        }
        return;
    }
}